Skip to content

Add non-blocking file logging and stderr error logging#7

Merged
lukekim merged 1 commit into
mainfrom
lukim/logging
Apr 2, 2026
Merged

Add non-blocking file logging and stderr error logging#7
lukekim merged 1 commit into
mainfrom
lukim/logging

Conversation

@lukekim
Copy link
Copy Markdown
Contributor

@lukekim lukekim commented Apr 2, 2026

Summary

  • Add src/log.rs: non-blocking file logger backed by a dedicated OS thread with bounded mpsc::sync_channel(4096) and 64 KB BufWriter. try_send ensures the proxy is never blocked. Zero overhead when no file is configured.
  • Two macros: slog! (stdout) for lifecycle/info, serr! (stderr) for errors. Both tee to the log file when SPICEIO_LOG_FILE is set.
  • All log lines include ISO-8601 UTC timestamps with millisecond precision (2026-04-02T16:09:34.123Z) via gettimeofday — zero-alloc stack buffer, no external dependencies.
  • Log connection lifecycle (stdout): client TCP accept, SMB TCP connect, negotiate, auth, tree connect.
  • Log all failure paths (stderr): every SMB wire error, S3 streaming errors, body read errors, access denied, client disconnects.

Test plan

  • make lint passes (fmt, check, clippy, rustdoc)
  • cargo test --locked — 200/200 tests pass
  • sccache integration test passes against NAS (14/14 S3 API tests, 87 cache hits)
  • Verified file logging output with SPICEIO_LOG_FILE — timestamps, stdout/stderr routing, and file tee all working

Add a lightweight logging system with two macros — slog! (stdout) and
serr! (stderr) — that also tee to a log file via SPICEIO_LOG_FILE. The
file writer runs on a dedicated OS thread fed by a bounded mpsc channel;
try_send ensures logging never blocks the proxy. When no file is
configured there is zero overhead (no thread, no channel, no allocation).

All log lines are timestamped (ISO-8601 UTC with milliseconds) using
gettimeofday — no allocations in the timestamp path.

Also adds logging for:
- Connection lifecycle (stdout): client TCP accept, SMB TCP connect,
  negotiate, auth, tree connect
- All failure paths (stderr): every SMB wire error, S3 streaming errors,
  body read errors, access denied, client disconnects
@lukekim lukekim merged commit f32135d into main Apr 2, 2026
1 check passed
@lukekim lukekim deleted the lukim/logging branch April 2, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant